package org.example.im.client.console.impl;

import io.netty.channel.Channel;
import org.example.im.bean.protocol.request.LoginRequestPacket;
import org.springframework.stereotype.Component;

import java.util.Scanner;

/**
 * @author dingrui
 * @since 2022/2/12
 * @description 登录
 */
@Component
public class LoginCommand {

    public void exec(Scanner s, Channel c) {
        System.out.println("[C-Login] 登录界面 输入登录用户名: ");
        String userName = s.nextLine();
        System.out.println("[C-Login] 输入登录密码: ");
        String password = s.nextLine();
        // 登录包
        c.writeAndFlush(LoginRequestPacket.builder().userName(userName).password(password).build());
        // sleep
        this.wait4LoginResponse();
    }

    private void wait4LoginResponse() {
        try {
            Thread.sleep(1_000);
        } catch (InterruptedException e) {
            // ignore
        }
    }
}
